####################################################################################
#                         TITLE.  #
# Author; THE AWESOME ERIN GRAHAM                                            #
# Last modified: DATE                                                 #
###################################################################################

## This R file contains the code necessary to replicate the analysis in the main text.
## The analysis was carried out using R version 3.5.2 on a 3.5 GHz Intel Core i7 running OS Sierra 10.12.6

#loading packages (function from Huff and Kertzer 2017)
ipak <- function(pkg){  new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
                        if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
                        sapply(pkg, require, character.only = TRUE)
}

packages <- c("foreign","Exact") 
ipak(packages)

#Create a contingency table or matrix:
VOTE_FUND <-
matrix(c(1, 4, 13, 0),
       nrow = 2,
       dimnames = list(Fund = c("NoEarma", "YesEarma"),
                       Vote = c("OneStOneVote", "Weighted")))
#Visualize the table (to make sure it makes sense)                     
                     VOTE_FUND
 
# Fisher's exact test                      
fisher.test(VOTE_FUND, alternative = "two.sided")
# Fisher's exact test rejects the claim of independence between voting and funding (p-value = 0.001)
# Barnard's test:
exact.test(VOTE_FUND, method="CSM", alternative="two.sided",to.plot=FALSE)
#We reject the null that the true difference in proportions is equal to zero (p-value = 0.001)



